home *** CD-ROM | disk | FTP | other *** search
/ Alpha CD-ROM Bonus Pack / Alpha CD-ROM Bonus Pack.iso / life / shared.dir / 00504_MouseInDialog.ls < prev    next >
Encoding:
Text File  |  1995-01-16  |  3.9 KB  |  118 lines

  1. on dlogInit
  2.   global dlogNameList, dlogLocationList, dlogSpriteList, dlogButtonList, dlogButtonLocationList, dlogButtonSprites
  3.   setDialogOpen(0)
  4.   set dlogNameList to ["quitDialog"]
  5.   set dlogLocationList to [[140, 140]]
  6.   set dlogSpriteList to [46]
  7.   set dlogButtonList to [[#Yes: 47, #No: 48]]
  8.   set dlogButtonLocationList to [[[240, 90], [70, 90]]]
  9. end
  10.  
  11. on openDialog dialogBoxName
  12.   global dlogNameList, dlogLocationList, dlogSpriteList, dlogButtonList, dlogButtonLocationList, dlogButtonSprites
  13.   set the mouseDownScript to "beepIfOutsideDialog"
  14.   set theIndex to getPos(dlogNameList, dialogBoxName)
  15.   set cNum to the number of cast dialogBoxName
  16.   set X to getX(getAt(dlogLocationList, theIndex))
  17.   set Y to getY(getAt(dlogLocationList, theIndex))
  18.   set sNum to getAt(dlogSpriteList, theIndex)
  19.   if cNum > 0 then
  20.     setDialogOpen(dialogBoxName)
  21.     puppetSprite(sNum, 1)
  22.     set the castNum of sprite sNum to cNum
  23.     set the locH of sprite sNum to X
  24.     set the locV of sprite sNum to Y
  25.     set theButtonList to getAt(dlogButtonList, theIndex)
  26.     set theLocList to getAt(dlogButtonLocationList, theIndex)
  27.     repeat with i = 1 to count(theButtonList)
  28.       set sButton to getAt(theButtonList, i)
  29.       puppetSprite(sButton, 1)
  30.       set the castNum of sprite sButton to the number of cast (string(getPropAt(theButtonList, i)) & "_B1")
  31.       set the locH of sprite sButton to X + getX(getAt(theLocList, i))
  32.       set the locV of sprite sButton to Y + getY(getAt(theLocList, i))
  33.     end repeat
  34.     updateStage()
  35.   end if
  36. end
  37.  
  38. on checkDialogs
  39.   global dlogNameList, dlogLocationList, dlogSpriteList, dlogButtonList, dlogButtonLocationList, dlogButtonSprites, movieFileExtension
  40.   set theDialog to "quitDialog"
  41.   set cNum to the number of cast theDialog
  42.   if isDialogOpen() = EMPTY then
  43.     return 0
  44.   else
  45.     if isDialogOpen() = theDialog then
  46.       set theIndex to getPos(dlogNameList, theDialog)
  47.       set theButtonList to getAt(dlogButtonList, theIndex)
  48.       if buttonClicked(theButtonList, #Yes, 1) then
  49.         closeDialog(theDialog)
  50.         play movie "quit" & movieFileExtension
  51.       else
  52.         if buttonClicked(theButtonList, #No, 1) then
  53.           closeDialog(theDialog)
  54.         end if
  55.       end if
  56.     end if
  57.   end if
  58.   return 1
  59. end
  60.  
  61. on closeDialog dialogBoxName
  62.   global dlogNameList, dlogLocationList, dlogSpriteList, dlogButtonList, dlogButtonLocationList, dlogButtonSprites
  63.   set theIndex to getPos(dlogNameList, dialogBoxName)
  64.   set cNum to the number of cast "EmptyPaintObject"
  65.   set sNum to getAt(dlogSpriteList, theIndex)
  66.   if (cNum > 0) and (sNum > 0) and (sNum < 48) then
  67.     setDialogOpen(EMPTY)
  68.     puppetSprite(sNum, 1)
  69.     set the castNum of sprite sNum to cNum
  70.     set theButtonList to getAt(dlogButtonList, theIndex)
  71.     repeat with i = 1 to count(theButtonList)
  72.       set sButton to getAt(theButtonList, i)
  73.       puppetSprite(sButton, 1)
  74.       set the castNum of sprite sButton to cNum
  75.     end repeat
  76.     updateStage()
  77.     set the mouseDownScript to EMPTY
  78.   end if
  79. end
  80.  
  81. on setDialogOpen theDialog
  82.   global gCurrentDialog
  83.   set gCurrentDialog to theDialog
  84. end
  85.  
  86. on isDialogOpen
  87.   global gCurrentDialog
  88.   return gCurrentDialog
  89. end
  90.  
  91. on mouseInDialogBox dialogBoxSprite
  92.   global sDialogBox
  93.   if (the mouseH < the left of sprite dialogBoxSprite) or (the mouseH > the right of sprite dialogBoxSprite) or (the mouseV < the top of sprite dialogBoxSprite) or (the mouseV > the bottom of sprite dialogBoxSprite) then
  94.     return 0
  95.   else
  96.     return 1
  97.   end if
  98. end
  99.  
  100. on beepIfOutsideDialog
  101.   global dlogNameList, dlogLocationList, dlogSpriteList, dlogButtonList, dlogButtonLocationList, dlogButtonSprites
  102.   set theDialog to "quitDialog"
  103.   if isDialogOpen() = EMPTY then
  104.     exit
  105.   else
  106.     if isDialogOpen() = theDialog then
  107.       set theIndex to getPos(dlogNameList, theDialog)
  108.       set sNum to getAt(dlogSpriteList, theIndex)
  109.       if mouseInDialogBox(sNum) then
  110.         exit
  111.       else
  112.         beep()
  113.         dontPassEvent()
  114.       end if
  115.     end if
  116.   end if
  117. end
  118.